<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <base th:href="@{/}">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>重置密码</title>

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/bootstrap.min.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/fonts/line-icons.css}">

    <link rel="stylesheet" th:href="@{/assets/plugins/morris/morris.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/main.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/responsive.css}">

    <link rel="stylesheet" th:href="@{https://use.fontawesome.com/releases/v5.5.0/css/all.css}" crossorigin="anonymous">

    <script th:src="@{/assets/js/jquery-min.js}"></script>
    <script th:src="@{/assets/js/jquery-min.js}"></script>
    <script>
        $(function () {
            $("#passwordNewTips").hide();
            $("#passwordTips").hide();
        });

        function check(){
            var passwordNew =$("#passwordNew").val();
            var passwd =$("#password").val();
            var id=$("#id").val(); //获取选中的项
            var data = {"id":id,"passwd":passwd};
            var reg = /^.{6,}$/;


                if (passwordNew!=""){
                    if (!reg.test(passwordNew)) {
                        $("#passwordNewTips").show();
                        $("#passwordNewTips").html("密码至少六位");
                        $("#passwordTips").hide();
                    }else{
                        $("#passwordNewTips").hide();
                        if(passwd!=""){
                            $("#passwordTips").hide();
                            if (passwd!=passwordNew){
                                $("#passwordTips").html("两次输入密码不匹配");
                                $("#passwordTips").show();
                            }else {
                                $.ajax({
                                    url:"/front/user/updatePassword",
                                    dataType:"json",
                                    type:"post",
                                    data:data,
                                    success:function(data){
                                        if (data!="0"){
                                            $("#passwordTips").html("修改成功，赶紧去登录吧");
                                            $("#passwordTips").show();
                                            window.open("/front/user/login", "_self");
                                        }else {
                                            $("#passwordTips").html("修改失败");
                                            $("#passwordTips").show();
                                        }
                                    },
                                    error:function(){
                                        $("#passwordTips").html("修改失败");
                                        $("#passwordTips").show();
                                    }
                                });
                            }
                        }else {
                            $("#passwordTips").html("* 确认密码不能为空");
                            $("#passwordTips").show();
                        }
                    }
                }else {
                    $("#passwordNewTips").html("* 新密码不能为空");
                    $("#passwordNewTips").show();
                    $("#passwordTips").hide();
                }


        }
    </script>

</head>
<body>
<div class="app header-default side-nav-dark">
    <div class="layout">
        <div class="header navbar">
            <div class="header-container">
                <ul class="nav-left">
                    <li>
                        <a href="javascript:history.back(-1);">
                            <i class="lni-chevron-left" style="border: transparent;"></i>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="page-container" style="padding: 64px 0 0 0!important;">
            <div class="main-content" style="padding-top: 15px!important;">
                <div class="container-fluid">
                    <div class="card">
                        <div class="card-header border-bottom">
                            <h4 class="card-title">修改密码</h4>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-10 col-md-12 col-xs-12">
<!--                                    <form action="/front/user/sureUpdate" role="form" id="form-validation" novalidate="novalidate" method="post" >-->

                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label control-label">
                                                <span>新密码</span>
                                                <p style="color: red;display: inline-block!important;font-size: 0.68rem;padding-left: 10px;margin-bottom: 0px;" id="passwordNewTips"></p></label>
                                            <div class="col-sm-10">
                                                <div>
                                                    <input type="password" class="form-control" name="passwordNew" placeholder="新密码" id="passwordNew">
                                                    <input type="text" style="display: none" class="form-control" name="id" id="id" th:value="${id}">
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label control-label">
                                                <span>确认密码</span>
                                                <p style="color: red;display: inline-block!important;font-size: 0.68rem;padding-left: 10px;margin-bottom: 0px;" id="passwordTips"></p>
                                            </label>
                                            <div class="col-sm-10">
                                                <div>
                                                    <input type="password" class="form-control" name="password" placeholder="确认密码" id="password">
                                                </div>
                                            </div>
                                        </div>

                                        <button class="btn btn-outline-success" onclick="check()">
                                            <span>确认</span>
                                        </button>
<!--                                    </form>-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<div id="preloader">
    <div class="loader" id="loader-1"></div>
</div>

<script th:src="@{/assets/js/popper.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/jquery.app.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>

<script th:src="@{/assets/plugins/morris/morris.min.js}"></script>
<script th:src="@{/assets/plugins/raphael/raphael-min.js}"></script>
<!--<script th:src="@{/assets/js/dashborad1.js}"></script>-->

<script th:src="@{https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js}" crossorigin="anonymous"></script>

</body>

</html>